$(function () {
    var markid = getUrlString('markid');
    var page = 0,totalSize = 0,sort= 11;
    cashCommodityList(0,sort);
    function cashCommodityList (page,sort) {
        layLoading();
        var data = {
            'markid':markid,
            'mainstate':1,
            'type':2,
            'sort':sort,
            'page':page
        };
        getData('post','/niu/apiv4/buy_back_list.php',data,function (data) {
            console.log(data);
            layer.closeAll('loading');
            if(data.resultcode === '0' ){
                var append = '';

                $(data.data).each(function () {
                    if (this.lockon === '0'){
                        if (this.toylevel < 2){
                            append += '<li>' +
                                '            <input class="kuid" type="hidden" value="'+this.id+'">'+
                                '            <input class="paypoint" type="hidden" value="'+this.paypoint+'">'+
                                '            <div class="pic">' +
                                '                <img src="'+this.pics+'-toysbox11'+'" alt="">' +
                                '                <img class="noCheck" src="../../res/img/my/myEggPool/noCheck.png" alt="">' +
                                '                <img class="check" src="../../res/img/my/myEggPool/check.png" alt="">' +
                                '            </div>' +
                                '            <div class="name">'+
                                '            <div>'+this.name+'</div>'+
                                '            <div class="hgjg">' +
                                '               <span>回购价</span>' +
                                '               <img src="../../res/img/common/goldCoin.png" alt="">' +
                                '               <span class="ghprice">'+this.paypoint+'</span>' +
                                '               <div class="dayNum">'+this.outtime+'</div>'+
                                '             </div> '+
                                '           </div>' +

                                '        </li>'
                        }
                    }

                });
                $('#cashCommodityList').append(append);
                $('#loaded').show();
                //点击选择商品
                $('#cashCommodityList li').click(function () {
                    if($(this).hasClass('selected')){
                        $(this).removeClass('selected');
                        $(this).find('.pic').children('.check').hide();
                        $(this).children('.kuid').removeClass('forId');
                        $(this).children('.paypoint').removeClass('forPrice');
                    }else {
                        $(this).addClass('selected');
                        $(this).find('.pic').children('.check').show();
                        $(this).children('.kuid').addClass('forId');
                        $(this).children('.paypoint').addClass('forPrice');
                    }
                });

                //全选
                $('.checkAllSelected').click(function () {
                    $(this).hide();
                    $('.cashCommodityList li').addClass('selected');
                    $('.kuid').addClass('forId');
                    $('.paypoint').addClass('forPrice');
                    $('.check,.noCheckAll').show();
                });

                //取消全选
                $('.noCheckAll').click(function () {
                    $('.check,.noCheckAll').hide();
                    $('.cashCommodityList li').removeClass('selected');
                    $('.kuid').removeClass('forId');
                    $('.paypoint').removeClass('forPrice');
                    $('.checkAllSelected').show();
                });
                // mRefresh.endUpLoading(true);
            }else {
                laymsg(data.msg)
            }
        })
    }

    let pickUpStr = '';
    $('.pickUpBtn').click(function () {
        let pickUpArr = [];
        $('.forId').each(function () {
            pickUpArr.push($(this).val());
        });
        pickUpStr = pickUpArr.join(';');
        if (pickUpStr === ''){
            laymsg('请选择挂卖商品')
        } else {
            let kutoysid = pickUpStr.replace(/;/g,',');
            window.location.href="dancool://fullweb="+urlView+"my/batchGMDetail.html?id="+kutoysid;
            // checktoys(pickUpStr);
        }

    });

});
